package com.pb.wkflow.api.controller.assembler;

import com.alibaba.fastjson.JSON;
import com.pb.wkflow.api.controller.request.ProcessInstanceCreateRequest;
import com.pb.wkflow.api.entity.WfSysProcInfoEntity;
import com.pb.wkflow.core.config.DeleteReasonConstants;
import com.pb.wkflow.core.utils.SnowFlake;
import org.camunda.bpm.engine.repository.ProcessDefinition;
import org.camunda.bpm.engine.runtime.ProcessInstance;

/**
 * WfSysProcInfoAssembler
 * @author 苗益辉
 * @date 2022/9/28 9:40
 */
public class WfSysProcInfoAssembler {

    private WfSysProcInfoAssembler() {

    }

    public static WfSysProcInfoEntity assemblerToInsert(ProcessDefinition processDefinition,
                                                        ProcessInstance processInstance, ProcessInstanceCreateRequest request) {
        return WfSysProcInfoEntity.builder()
                .id(SnowFlake.nextId())
                .procDefId(processDefinition.getId())
                .procDefKey(processDefinition.getKey())
                .procDefName(processDefinition.getName())
                .procInstId(processInstance.getId())
                .classify(processDefinition.getCategory())
                .title(request.getTitle())
                .startUserId(request.getStartUserId())
                .startUserName(request.getStartUserName())
                .startOrgId(request.getStartUserOrg())
                .startOrgName(request.getStartUserOrgName())
                .startTime(request.getNowDate())
                .processStatus(DeleteReasonConstants.START)
                .paramMap(JSON.toJSONString(request.getGlobalVariables()))
                .tenantId(request.getTenantId())
                .field1(request.getField1())
                .field2(request.getField2())
                .field3(request.getField3())
                .field4(request.getField4())
                .field5(request.getField5()).build();

    }
}
